package com.itheima.genericit;

public class StudentData implements Data<Student>{
    private MyArrayList<Student> students = new MyArrayList<>();
    @Override
    public void add(Student student) {
        System.out.println("添加学生信息成功");
        students.add(student);
    }

    @Override
    public void delete(Student student) {
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if(s.getId() == student.getId()) {
                students.remove(i);
                System.out.println("删除学生信息成功");
                return;
            }
        }

    }

    @Override
    public void update(Student student) {

        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if(s.getId() == student.getId()) {
                students.set(i, student);
                System.out.println("修改学生信息成功");
                return;
            }
        }
    }

    @Override
    public Student get(int id) {
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if(s.getId() == id) {
                return s;
            }
        }
        return null;
    }
}
